#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@File ：CouponController.py
@Author ：zqy
@Email : zqingy@work@163.com 
@note: 
"""

from flask_restx import Namespace, Resource

from application.Parser import with_parser
from application.Parser.CouponParser import CouponValidator
from application.controller import register_crud_model
from application.logic.CouponLogic import CouponLogic
from application.util.ResponseUtil import ResponseUtil

coupon_ns = Namespace('coupon', description='优惠券模块')
coupon_parser: CouponValidator = CouponValidator
register_crud_model(
    ns=coupon_ns,
    logic_cls=CouponLogic,
    parser=coupon_parser,
    route="",
    id_type="int",
    include_operations=["get", "list"]
)


@coupon_ns.route('/')
class CouponController(Resource):
    p = coupon_parser.post()

    @with_parser(p)
    def post(self):
        return ResponseUtil(data=CouponLogic.post(self.p.parse_args())).success()


@coupon_ns.route('/<int:id>')
class CouponController(Resource):
    def delete(self, id):
        return ResponseUtil(data=CouponLogic.delete(id)).success()
